package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.vo.ExternalLinkDeleteVO;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.ExternalLinkPageAdminDTO;
import com.sc.nft.entity.dto.ExternalLinkSaveAdminDTO;
import com.sc.nft.entity.dto.ExternalLinkUpdateAdminDTO;
import com.sc.nft.entity.vo.AdminExternalLinkListVO;
import com.sc.nft.service.ExternalLinkService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/externalLink")
@Api(tags = "外链操作")
public class ExternalLinkController {

    private final ExternalLinkService externalLinkService;

    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除", notes = "删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ExternalLinkDeleteVO> deleteById(@Validated @RequestBody IdRequest idRequest) {
        ExternalLinkDeleteVO externalLinkDeleteVO = new ExternalLinkDeleteVO();
        externalLinkDeleteVO.setResult(externalLinkService.deleteById(idRequest.getId()));
        return Result.success(externalLinkDeleteVO);
    }


    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "后台获取用户的外链列表", notes = "后台获取用户的外链列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<Page<AdminExternalLinkListVO>> pageAdmin(@Validated @RequestBody ExternalLinkPageAdminDTO externalLinkPageAdminDTO) {
        return PageResult.success(externalLinkService.pageAdmin(externalLinkPageAdminDTO));
    }


    @PostMapping(value = "/updateById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "根据id修改用户的链接", notes = "根据id修改用户的链接", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ExternalLinkDeleteVO> updateById(@Validated @RequestBody ExternalLinkUpdateAdminDTO externalLinkUpdateAdminDTO) {
        ExternalLinkDeleteVO externalLinkDeleteVO = new ExternalLinkDeleteVO();
        externalLinkDeleteVO.setResult(externalLinkService.updateById(externalLinkUpdateAdminDTO));
        return Result.success(externalLinkDeleteVO);
    }


    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ExternalLinkDeleteVO> save(@Validated @RequestBody ExternalLinkSaveAdminDTO externalLinkSaveAdminDTO) {
        ExternalLinkDeleteVO externalLinkDeleteVO = new ExternalLinkDeleteVO();
        externalLinkDeleteVO.setResult(externalLinkService.save(externalLinkSaveAdminDTO));
        return Result.success(externalLinkDeleteVO);
    }


}
